#include<iostream>
#include<string>
#include<vector>

int Split(const std::string&str,const std::string &sep,std::vector<std::string>*arry)
{
    int count=0;
    size_t pos=0,idx=0;
    while(1)
    {
        //abc bcd def
        //find（要查找的字符，从哪里开始查找的偏移量）
        pos=str.find(sep,idx);
        if(pos==std::string::npos)
        {
            break;
        }
        if(pos==idx)
        {
            idx=pos+sep.size();
            continue;
        }
        //substr(截取起始位置，长度)
        std::string tmp=str.substr(idx,pos-idx);
        arry->push_back(tmp);
        count++;
        idx=pos+sep.size();
    }
    if(idx<str.size())
    {
        arry->push_back(str.substr(idx));
        count++;
    }
    return count;
}
int main()
{
    std::string str="abc cde  vfr ";
    std::vector<std::string>arry;
    Split(str," ",&arry);
    for(auto&a:arry)
    {
        std::cout<<a<<std::endl;
    }
    return 0;
}